﻿using System;
using System.Windows;
using Microsoft.Expression.Framework;
using Microsoft.Expression.Framework.Commands;
using Oxage.Rasterizer.Views;

namespace Oxage.Rasterizer.Blend.AddIn
{
	public class RasterAddIn : CommandTarget, IPackage
	{
		private IApplicationService appService;
		private RasterView view;

		public void Initialize()
		{
			try
			{
				var contractService = new RasterContractService(appService);

				this.view = new RasterView();
				this.view.ViewModel.RegisterContractService(contractService);

				appService.CommandService.AddTarget(this);

				if (appService.WindowService.PaletteRegistry["xbraster"] == null)
				{
					appService.WindowService.RegisterPalette("xbraster", this.view, "Rasterizer");
				}
			}
			catch (Exception ex)
			{
				if (Settings.Debug)
				{
					MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
				}
			}
		}

		public void Load(IApplicationService applicationService)
		{
			appService = applicationService;
			Initialize();
		}

		public void Unload()
		{
		}
	}
}